import { SelectControlSchema } from 'amis/lib/renderers/Form/Select'
import serverSelectUtils, { ServerSelectUtilsProps } from '@/components/amis/ServerSelectUtils/serverSelectUtils'

import lodash from 'lodash'
import upmsAdminApiConfig from '@/core/upms/generated/apiconfig/upmsAdminApiConfig'

class UpmsAuthorityIdSelectUtils {
	getSchema = (parmas?: Partial<ServerSelectUtilsProps>): SelectControlSchema => {
		let mergeProps = lodash.merge(
			{
				label: '权限资源',
				name: 'upmsAuthoriId',
				labelField: 'title',
				searchField: 'title',
				valueField: 'id',
				options: [{ label: '-', value: '0' }],
				detailApiConfig: upmsAdminApiConfig.upmsAuthority.get,
				searchApiConfig: upmsAdminApiConfig.upmsAuthority.search,
			} as ServerSelectUtilsProps,
			parmas,
		)
		const name = mergeProps.name
		mergeProps.sourceSendOn = `this.${name} && this.${name} !== "" && this.${name} !== undefined && this.${name} !== null && this.${name} !== "0"`
		return serverSelectUtils.getSchema(mergeProps)
	}
}

export default new UpmsAuthorityIdSelectUtils()
